<?php
header("Content-Type: application/rss+xml; charset=utf-8");
require_once('../lib/diy.php');

$smarty = new Smarty_DiyCity();
$smarty->caching = 1;
/* Cache expire time : 6 hours */
$smarty->cache_lifetime = 3600 * 6;

if ($smarty->is_cached('rss.tpl', $_GET['url']))
  {
    $smarty->display('rss.tpl', $_GET['url']);
  }
 else
   {
     require_once('../lib/model.php');
     $address = explode('/', $_GET['url']);
     $m = new DiyModel('problems');

     switch(sizeof($address)) {
     case 1:
       $params = array('conditions' => array('address1' => $address[0]),
		       'order' => 'id desc');
       break;
     case 2:
       $params = array('conditions' => array('address1' => $address[0],
					     'address2' => $address[1]),
		       'order' => 'id desc');
       break;
     case 3:
       $params = array('conditions' => array('address1' => $address[0],
					     'address2' => $address[1],
					     'address3' => $address[2]),
		       'order' => 'id desc');
       break;
     }

     $result = $m->find('all', $params);
     if (sizeof ($result) == 0)
       {
	 /* Just empty page */
	 $smarty->caching = 0;
	 $smarty->assign('address', implode(" ", $address));
	 $smarty->assign('lastBuildDate', date(DATE_RFC2822));
	 $smarty->display('empty.tpl');
       }
     else
       {
	 $smarty->assign('address', implode(" ", $address));
	 $smarty->assign('lastBuildDate', date(DATE_RFC2822));
	 $smarty->assign('reports', $result);
	 $smarty->display('rss.tpl', $_GET['url']);
       }
   }
?>
